package com.szzg10.thinking.chapter18;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

public class Redirecting {

	public static void main(String[] args) throws IOException {
		File fileIn = new File(BufferedInputFile.FILE_NAME);
		FileInputStream fileInputStream = new FileInputStream(fileIn);
		BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
		
		File fileOut = new File(BasicFileOutput.FILE_NAME_OUT);
		FileOutputStream fileOutputStream = new FileOutputStream(fileOut);
		BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
		PrintStream printStream = new PrintStream(bufferedOutputStream);
		
		PrintStream console = System.out;
		System.setIn(bufferedInputStream);
		System.setOut(printStream);
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String str;
		while((str = reader.readLine()) != null) {
			System.out.println(str);
		}
		
		bufferedInputStream.close();
		printStream.close();
		
		System.setOut(console);
	}
}
